/**
 * Created by Administrator on 2015/2/7.
 */
"use strict";
var loginApp = angular.module("app.login", []);
loginApp.controller("login",['$scope','$http','$location','$timeout',function($scope,$http,$location,$timeout){
    $scope.loginInfo={};$scope.loginInfo.username=getCookieValue("userName");$scope.loginInfo.password=getCookieValue("userPwd");
    document.getElementById('save').checked = getCookieValue("checkSave");
    $scope.brand = '1.9.5';$scope.login = function(){
        if(document.getElementById('save').checked){
            setCookie("userName",$scope.loginInfo.username,24,"cookies");
            setCookie("userPwd",$scope.loginInfo.password,24,"cookies");
            setCookie("checkSave",document.getElementById('save').checked,24,"cookies");
        }
        $http({method  : 'post', url : 'login/oauth', data : $.param($scope.loginInfo),
            headers : { 'Content-Type': 'application/x-www-form-urlencoded' }}).success(function(data){
            if(!data.ret_data) $scope.login_error = data.ret_msg; else location.href = 'home';
        }).error(function(data){$scope.login_error = '请 求 已 发 出 请 等 待';});$timeout(function(){$scope.login_error = '';},5000);
    }
}]);loginApp.controller("crosslogin",['$scope','$location','$timeout',function($scope,$location,$timeout){
    $scope.time = 3;setInterval(function() {$scope.time--;$scope.$digest(); // 通知视图模型的变化
    }, 1000);$timeout(function(){location.href = 'login'},3000);
}]);
function setCookie(name,value,hours,path){
    var name = escape(name);var value = escape(value);var _expires = new Date();
    _expires.setTime(_expires.getTime() + hours*3600000);path = path == "" ? "" : ";path=" + path;
    _expires = (typeof hours) == "string" ? "" : ";expires=" + _expires.toUTCString();
    document.cookie = name + "=" + value + _expires + path;
}
function getCookieValue(name){
    var name = escape(name);var allcookies = document.cookie;name += "=";
    var pos = allcookies.indexOf(name);
    if (pos != -1){
        var start = pos + name.length;var end = allcookies.indexOf(";",start);
        if (end == -1) end = allcookies.length;
        var value = allcookies.substring(start,end);return (value);
    } else return "";
}

